home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / Codeworks 0.94b3 / Codeworks® WWW Demo Doc. / Extra.doc / Extra.doc.rsrc / TEXT_131.txt < prev    next >
Encoding:
Text File  |  1995-05-01  |  4.7 KB  |  69 lines

  1. Stream & File Objects
  2.  
  3.     Streams and Files are objects used for reading and writing text.  Streams read and write onto strings.  Files read and write onto files used for import and export.
  4.  
  5.     Streams and Files are optimized for text, however, they can also be used to read raw bytes from strings and files.
  6.  
  7. ¬ª    The parent of File is Stream.  Remember that all of the messages of stream are available to files.
  8.  
  9. Reading
  10.     s read-byte return the numeric value of the next byte
  11.     s read-char return the next character
  12.     These read the next byte from the stream and return either its numeric value in the first case, or the character in the second.
  13.  
  14.  s read-field spacers w delimiters d    return the next field
  15.  This reads the next field from the stream.  The text in the stream is read up to and including the next delimiter, which can be any of the characters in the string d.  Before the read text is returned, the delimiter, and any white space at either end of the text (defined by characters in the string w) are removed.  The arguments spacers and delimiters default to the strings " " and "\t\r\n" respectively.  This defaults to reading tab delimited files nicely.  If the delimiters includes both CR and LF ("\r\n"), then all three end-of-line standards are handled automatically (see write-line below).
  16.  
  17.     s read-line return the next line    
  18.     s read-word return the next word
  19.     s read-number spacers w delimiters d
  20.         return the next field converted to a number
  21.     These are variants of read-field.  The first two default the arguments of field to read lines and words respectively.  The third message is just like read-field, only that afterward, the value is converted to a number (using the scan message).
  22.     
  23.     s read-string width n delimiters d    return the next string
  24.     This is similar to read-field, only the field is defined by the width argument, which is the number of characters in the field.  If any of the delimiters are reached, then the string is returned, even if it has too few characters.  The delimiters argument defaults to "\r\n".
  25.  
  26. Writing
  27.     s write-byte n    write a byte with numeric value n
  28.     s write-char c    write the character c
  29.     These write a single byte or a character to the stream.
  30.  
  31.  s write-field t delimiter d    write s followed by d
  32.     s write-word t        write s followed by a space
  33.  s write-number n using f delimiter d
  34.             format n and then write it followed by d
  35.     The first message writes the text t to the stream followed by the delimiter character d.  The second does the same, with a delimiter of a space.  The last message, first formats the number n using the format f (which default to the normal number formatting), and then writes it followed by the delimiter.
  36.  
  37.     s write-line t dos write t followed by a CR-LF sequence
  38.     s write-line t mac write t followed by a CR character
  39.     s write-line t unix write t followed by a LF character
  40.     s write-line t    defaults to dos
  41.     These messages write text out followed by one of the three standards for end-of-line.  If the text value t is omitted, then just the end-of-line sequence is written.
  42.  
  43.     s write-string t width n max m    write t out with size constraints
  44.     This writes out t to the stream.  If t is shorter than n, then extra spaces are written out to make it n characters long.  If t is longer than m, then 
  45.     only the first m characters are written.  Both width and max default to the size of t.
  46.  
  47.  
  48. Control
  49.     s.position    get the current position
  50.     s.position := n    set the current position
  51.     These get or set the current position in the stream.  This is the index of the next character from the stream to read.  [  There is a bug in that files are still zero based ].    
  52.  
  53.     s.at-end    return true if there are no more characters
  54.     
  55.     s skip n    move the current position by n
  56.     The skip value, n can be negative to move backwards.
  57.  
  58.     s.size    return the size of the stream
  59.     [ There is a bug in that this only works for files. ]
  60.  
  61. Creation
  62.     stream over t    return a new stream, reading the string t
  63.     
  64.  new file named n    open a file, create it if needed
  65.  new file named n create delete the file if it exists, the create it
  66.  new file named n exist generate an error if the file doesn‚Äôt exist
  67.     These create a new file object on the file named n.  You do not need to use this message for import and export as the file object is passed to your scripts as an argument.
  68.  
  69.     The name determines where the file is stored in PenPoint‚Äôs file structure, which is only visible to programmers.  If the file name is just a simple name (doesn‚Äôt start with a backslash character) then the file will be created inside a directory called FILES in the document directory.  If the file name begins with a single backslash, then it names a path on the current volume.  If the file name begins with two backslashes, then it names a volume and a full file path.